<template>
	<view>
		<view class="user">
			<view class="top">
				<image src="/static/images/浏览记录.png" mode=""></image>
				<view class="text">浏览历史</view>
			</view>
			<view class="content">
				<view class="row" v-for="item in listarr">
					<newsbox @click.native="godetail(item)" :item="item"></newsbox>
				</view>
			</view>
			<view class="nohistory" v-if="listarr.length==0">
				<image src="../../static/images/ico_没有数据.png" mode="widthFix"></image>
				<view class="text">暂无浏览记录</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listarr:[]
			};
		},
		onShow(){
			this.getdata()
		},
		methods:{
			// 跳转到详情页
			godetail(item){
				uni.navigateTo({
					url:`/pages/detail/detail?cid=${item.cid}&id=${item.id}`
				})
			},
			// 获取缓存中的浏览记录
			getdata(){
				let hisarr = uni.getStorageSync("historyarr") || [];
				this.listarr = hisarr;
				console.log(this.listarr)
			}
		}
	}
</script>

<style lang="scss">
	.user{
		.top{
			padding: 50rpx 0;
			background: #e4e4e4;
			color: #555;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;	
			image{
				width: 150rpx;
				height: 150rpx;
			}
		}
		.text{
			font-size: 36rpx;
			padding-top: 20rpx;
		}
	}
	.content{
		padding: 30rpx;
		.row{
			border-bottom: 1px dotted #efefef;
			padding: 20rpx 0;
		}
	}
	.nohistory{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width: 200rpx;
		}
		.text{
			font-size: 26rpx;
			color: #888;
		}
	}
</style>
